import { instance as request } from '../request'

/**
 * 获取角色列表
 * @returns
 */
export const getRoleListApi = (): PromiseRes<roleDetailItf[]> =>
  request.get('/role/roleList')

/**
 * 获取权限列表
 * @returns
 */
export const getPermissionsListApi = (): PromiseRes<permissionsDetailItf[]> =>
  request.get('/role/permissionsList')

/**
 * 获取角色权限详情
 * @param roleId  角色id
 * @returns
 */
export const getRolePermissionsDetailApi = (
  roleId: string
): PromiseRes<rolePermissionsDetailItf[]> =>
  request.get(`/role/rolePermissionsDetail/${roleId}`)

/**
 * 为角色设置权限
 * @param roleId 角色id
 * @param permissionsList   权限id 列表
 * @returns
 */
export const setRolePermissionsApi = (
  roleId: string,
  permissionsList: string[]
): PromiseRes =>
  request.post(`/role/setRolePermissions/${roleId}`, permissionsList)

/**
 * 获取用户角色详情
 * @returns
 */
export const getUserRolesApi = (): PromiseRes<roleUserDetailItf[]> =>
  request.get('/role/getUserRoles')

/**
 * 为用户设置角色(为登录用户)
 * @param roleList  角色id 列表
 * @returns
 */
export const setUserRolesApi = (roleList: string[]): PromiseRes =>
  request.post('/role/setUserRoles', roleList)
